package com.github.dengmin.mysql.shiro.jwt;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;

/**
 * @Author dengmin
 * @Created 2020/8/14 上午11:24
 */
@Slf4j
public class JwtCredentialsMatcher implements CredentialsMatcher {
    private static final long serialVersionUID = 1L;

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
        String token = authenticationToken.getCredentials().toString();
        String salt = authenticationInfo.getCredentials().toString();
        try{
            return JwtUtil.verifyToken(token, salt);
        }catch (Exception e){
            log.error("JWT token CredentialsMatcher Exception: "+ e.getMessage(), e);
        }
        return false;
    }
}
